package com.LeeCode;

/**
 * 二进制链表转整数
 */

public class Code1290 {
    public static void main(String[] args) {
        int[] nums = {1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0};
        ListNode head = Utils.arrayToListNode(nums);
        System.out.println(new Code1290().getDecimalValue(head));
    }

    public int getDecimalValue(ListNode head) {
        int ans = 0;
        while (head != null) {
            ans = (ans << 1) + head.val;
            head = head.next;
        }
        return ans;
    }
}
